package com.example.mydy.model;

import java.util.Date;

/**
 * 用户成就模型类
 */
public class Achievement {
    // 成就类型常量
    public static final int TYPE_ALL = 0;     // 所有类型
    public static final int TYPE_LOGIN = 1;   // 登录相关
    public static final int TYPE_TASK = 2;    // 任务相关
    public static final int TYPE_SOCIAL = 3;  // 社交相关
    public static final int TYPE_INCOME = 4;  // 收益相关

    // 成就等级
    public static final int LEVEL_BRONZE = 1;   // 铜级
    public static final int LEVEL_SILVER = 2;   // 银级
    public static final int LEVEL_GOLD = 3;     // 金级
    public static final int LEVEL_DIAMOND = 4;  // 钻石级

    // 成就ID
    private String id;
    
    // 成就名称
    private String name;
    
    // 成就描述
    private String description;
    
    // 成就图标资源ID
    private int iconResId;
    
    // 成就类型
    private int type;
    
    // 成就等级 (1-3: 铜/银/金)
    private int level;
    
    // 奖励活跃度点数
    private double reward;
    
    // 解锁条件数值
    private int targetValue;
    
    // 当前进度
    private int currentValue;
    
    // 成就解锁状态
    private boolean unlocked;
    
    // 解锁时间
    private long unlockTime;
    
    // 图标URL
    private String iconUrl;
    
    public Achievement(String id, String name, String description, int type, int level, int targetValue, double reward) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.type = type;
        this.level = level;
        this.currentValue = 0;
        this.targetValue = targetValue;
        this.reward = reward;
        this.unlocked = false;
        this.unlockTime = 0;
    }
    
    // 判断成就是否已完成
    public boolean isCompleted() {
        return currentValue >= targetValue;
    }
    
    // 获取成就等级名称
    public String getLevelName() {
        switch (level) {
            case 3:
                return "金";
            case 2:
                return "银";
            default:
                return "铜";
        }
    }
    
    // Getters and Setters
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    public int getIconResId() {
        return iconResId;
    }
    
    public void setIconResId(int iconResId) {
        this.iconResId = iconResId;
    }
    
    public int getType() {
        return type;
    }
    
    public void setType(int type) {
        this.type = type;
    }
    
    public int getLevel() {
        return level;
    }
    
    public void setLevel(int level) {
        this.level = level;
    }
    
    public double getReward() {
        return reward;
    }
    
    public void setReward(double reward) {
        this.reward = reward;
    }
    
    public int getTargetValue() {
        return targetValue;
    }
    
    public void setTargetValue(int targetValue) {
        this.targetValue = targetValue;
    }
    
    public int getCurrentValue() {
        return currentValue;
    }
    
    public void setCurrentValue(int currentValue) {
        this.currentValue = currentValue;
        if (this.currentValue >= this.targetValue && !this.unlocked) {
            this.unlocked = true;
            this.unlockTime = System.currentTimeMillis();
        }
    }
    
    public boolean isUnlocked() {
        return unlocked;
    }
    
    public void setUnlocked(boolean unlocked) {
        this.unlocked = unlocked;
    }
    
    public long getUnlockTime() {
        return unlockTime;
    }
    
    public void setUnlockTime(long unlockTime) {
        this.unlockTime = unlockTime;
    }
    
    public String getIconUrl() {
        return iconUrl;
    }
    
    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }
    
    // 获取完整成就名称，包含等级
    public String getFullName() {
        return name + "(" + getLevelName() + ")";
    }
    
    /**
     * 更新进度值
     * @param value 增加的值
     * @return 是否解锁成就
     */
    public boolean updateProgress(int value) {
        if (unlocked) {
            return false;
        }
        
        currentValue += value;
        
        if (currentValue >= targetValue) {
            setUnlocked(true);
            setUnlockTime(System.currentTimeMillis());
            return true;
        }
        
        return false;
    }
} 